﻿/********************************************************************************/
// <copyright file="BootStrapper.cs" company="Asia E-Business Solutions">
//     Copyright © 2012. All right reserved
// </copyright>
//
// <history>
//  <change who="Hieu Nguyen" date="17/12/2012 4:12:01 PM">Created</change>
// <history>
/********************************************************************************/

namespace JLL.China.Application
{
    using System.Data.Linq;
    using JLL.China.Infrastructure;
    using JLL.China.Infrastructure.Configuration;
    using JLL.China.Infrastructure.Logging;
    using JLL.China.Infrastructure.Repositories.LINQ2SQL;
    using Microsoft.Practices.Unity;
    using JLL.China.Infrastructure.Repositories.ApplicationConfig;
    using JLL.China.Infrastructure.Repositories.ProjectNames;
    using JLL.China.Infrastructure.Repositories.Admin;
    using JLL.China.Infrastructure.Repositories.Listings;
    using JLL.China.Infrastructure.Repositories.Event;
    using JLL.China.Infrastructure.Repositories.ListingMedia;
    using JLL.China.Infrastructure.Repositories.ProjectDirectoryMedia;
    using JLL.China.Infrastructure.Repositories.News;
    using JLL.China.Infrastructure.Repositories.ProjectDirectory;
    using JLL.China.Infrastructure.Repositories;
    public static  class BootStrapper
    {
        public static void Initialize()
        {
            var container = new UnityContainer();
            container.RegisterType<DataContext, JLLCHINADataContext>(new HttpContextLifetimeManager<JLLCHINADataContext>(),new InjectionConstructor());
            ObjectFactory.Container = container;
            
            container.RegisterType<ILogger, Log4net>(new ContainerControlledLifetimeManager());
            var logger = ObjectFactory.Resolve<ILogger>();
            logger.ConfigLog();

            RegisterRepositories(container);

            Globals.ConfigurationReader = new DefaultConfigurationReader();

            logger.Info("Bootstrapper Initializing completed");
        }
        private static void RegisterRepositories(IUnityContainer container)
        {
           
            
            container.RegisterType<IApplicationConfigRepository, ApplicationConfigRepository>(new ContainerControlledLifetimeManager());
            container.RegisterType<IProjectNamesRepository, ProjectNamesRepository>(new ContainerControlledLifetimeManager());
            container.RegisterType<IAdminRepository, AdminRepository>(new ContainerControlledLifetimeManager());
            container.RegisterType<IEventRepository, EventRepository>(new ContainerControlledLifetimeManager());
            container.RegisterType<IListingsRepository, ListingsRepository>(new ContainerControlledLifetimeManager());
            container.RegisterType<IListingMediaRepository, ListingMediaRepository>(new ContainerControlledLifetimeManager());
            container.RegisterType<INewsRepository, NewsRepository>(new ContainerControlledLifetimeManager());
            container.RegisterType<IProjectDirectoryRepository, ProjectDirectoryRepository>(new ContainerControlledLifetimeManager());

            container.RegisterType<IProjectDirectoryMediaRepository, ProjectDirectoryMediaRepository>(new ContainerControlledLifetimeManager());
        }
    }
}
